package cn.ekuma.epos.finance.model;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.db.table.I_CloseCash;
import com.openbravo.bean.CloseCash;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.IntegerUtils;
import com.openbravo.pos.util.RoundUtils;

public class CashBookTableModel extends AbstractDTOTableModel<CloseCash>{

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		CloseCash obj=this.getObj(rowIndex);
		switch(columnIndex){
		case 0:
			return obj.getHost();
		case 1:
			return obj.getHostSequence();
		case 2:
			return obj.getName();
		case 3:
			return Formats.TIMESTAMP.formatValue(obj.getDataStart());
		case 4:
			return Formats.TIMESTAMP.formatValue(obj.getDataEnd());
		case 5:
			return obj.getPaymentNum();
		case 6:
			return RoundUtils.round(obj.getPaymentsTotal());
		case 7:
			return RoundUtils.round(obj.getHandCash());
		case 8:
			return obj.getSaleNum();
		case 9:
			return RoundUtils.round(obj.getSalesBase());
		case 10:
			return RoundUtils.round(obj.getSalesTaxes());
		case 11:
			return RoundUtils.round(obj.getSalesBase()+obj.getSalesTaxes());
		case 12:
			return obj.getMemo();
		}
		return null;
	}

  private static int[] doubleInt={6,7,9,10,11};
	
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if(IntegerUtils.concat(columnIndex, doubleInt))
			return Double.class;
		return super.getColumnClass(columnIndex);
	}
	
	
	@Override
	public String[] getColumnNames() {
		
		return new String[]{
				AppLocal.getIntString("label.hostName"),
				AppLocal.getIntString("label.sequence"),
				AppLocal.getIntString("label.closecash.name"),
				AppLocal.getIntString("Label.StartDate"),
				AppLocal.getIntString("Label.EndDate"),
				
				AppLocal.getIntString("Label.Tickets"),
				AppLocal.getIntString("Label.Cash"),
				AppLocal.getIntString("label.handedCash"),
				AppLocal.getIntString("label.sales"),
				AppLocal.getIntString("label.subtotalcash"),
				
				AppLocal.getIntString("label.taxcash"),
				AppLocal.getIntString("label.totalcash"),
				AppLocal.getIntString("label.notes")
		};
	}
	
	public static Field[] getQBFFields(){
		return new Field[]{
				new Field(I_CloseCash.HOST,   Datas.STRING, Formats.STRING, AppLocal.getIntString("label.hostName")),
                new Field(I_CloseCash.HOSTSEQUENCE,     Datas.INT, Formats.INT,AppLocal.getIntString("label.sequence")),
                new Field(I_CloseCash.NAME, Datas.STRING,Formats.STRING,AppLocal.getIntString("label.closecash.name")),
                new Field(I_CloseCash.DATESTART,      Datas.TIMESTAMP,Formats.TIMESTAMP,AppLocal.getIntString("Label.StartDate")),
                new Field(I_CloseCash.DATEEND,      Datas.TIMESTAMP,Formats.TIMESTAMP,AppLocal.getIntString("Label.EndDate")),
                new Field(I_CloseCash.PAYMENTNUM,     Datas.STRING,Formats.STRING, AppLocal.getIntString("label.notes")),
                new Field(I_CloseCash.PAYMENTSTOTAL,   Datas.DOUBLE, Formats.CURRENCY,AppLocal.getIntString("label.maxdebt")),
                new Field(I_CloseCash.SALENUM,   Datas.INT,Formats.INT,AppLocal.getIntString("label.curdate")),
                new Field(I_CloseCash.SALESBASE,   Datas.DOUBLE,Formats.DOUBLE,AppLocal.getIntString("label.curdate")),
                new Field(I_CloseCash.SALESTAXES,   Datas.DOUBLE,Formats.DOUBLE,AppLocal.getIntString("label.curdate"))
            };
	}
}
